package cn.jsj.cxsys.controller;

import cn.jsj.cxsys.controller.packageClass.IntInt;
import cn.jsj.cxsys.dao.UserFunction;
import cn.jsj.cxsys.service.ComputerService;
import cn.jsj.cxsys.service.StudentLabService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.List;

@Component
public class IntimeRunner {

    @Autowired
    private StudentLabService studentLabService;

    @Autowired
    private ComputerService computerService;

    @Resource
    private UserFunction userFunction;

    @Scheduled(cron="0 30 22 * * ?")//添加定时任务
    public void refreshOneDay(){
        System.out.println("每日定时例行签退");
        List<IntInt> storage = this.userFunction.getOnlineUsers();
        if(storage == null || storage.size()==0){
            return;
        }
        for(IntInt i: storage){
            if(i.getComputerID()==0){
                this.studentLabService.studentSignOutLab(this.userFunction.getOneStudentById(i.getUserID()),"系统每日自动签退");
            }else{
                this.computerService.signOutComputer(this.userFunction.getOneStudentById(i.getUserID()),i.getComputerID(),"系统每日自动签退");
            }
        }
    }

}
